package classes.web;

import org.junit.Test;

import java.io.*;
import java.net.*;

public class TCPServerTest {
    @Test
    public void test() {
        ServerSocket localhost = null;
        Socket s = null;
        try {
            localhost = new ServerSocket(9999);
            s = localhost.accept();  //等待连接
            InputStream inputStream = s.getInputStream();
            OutputStream outputStream = s.getOutputStream();
            byte[] bytes = new byte[10];
            inputStream.read(bytes);
            System.out.println(new String(bytes));

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (localhost != null) {
                try {
                    localhost.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (s != null) {
                try {
                    s.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
